
#ifndef __GAMEMUSIC_H__
#define __GAMEMUSIC_H__

#include <dmusici.h>
#include <dmusicc.h>
#include <dmusicf.h>

#define DM_NUM_SEGMENTS 64 // number of midi segments that can be cached in memory

// midi object state defines
#define MIDI_NULL     0   // this midi object is not loaded
#define MIDI_LOADED   1   // this midi object is loaded
#define MIDI_PLAYING  2   // this midi object is loaded and playing
#define MIDI_STOPPED  3   // this midi object is loaded, but stopped


// Convert from multibyte format to Unicode using the following macro:
#define MULTI_TO_WIDE( x,y )  MultiByteToWideChar( CP_ACP,MB_PRECOMPOSED, y,-1,x,_MAX_PATH);

// initializes a direct draw struct
#define DD_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); }

// directmusic MIDI segment
typedef struct DMUSIC_MIDI_TYP
{
IDirectMusicSegment        *dm_segment;  // the directmusic segment
IDirectMusicSegmentState   *dm_segstate; // the state of the segment
int                        id;           // the id of this segment               
int                        state;        // state of midi song

} DMUSIC_MIDI, *DMUSIC_MIDI_PTR;


class CGameMusic
{
public:
	CGameMusic();
	virtual ~CGameMusic();

	int		Init(HWND hWnd, LPDIRECTSOUND lpds);

	int Load_MIDI(char *filename);
	int Play(int id);
	int Stop(int id);
	int Shutdown();
	int Delete_MIDI(int id);
	int Delete_All_MIDI();
	int Status_MIDI(int id);

protected:

	// direct music globals
	IDirectMusicPerformance    *	m_dm_perf;			// the directmusic performance manager 
	IDirectMusicLoader         *	m_dm_loader;		// the directmusic loader

	// this hold all the directmusic midi objects
	DMUSIC_MIDI						m_dm_midi[DM_NUM_SEGMENTS];
	int								m_dm_active_id;     // currently active midi segment

	HWND							m_hWnd;
};


#endif